module stopwatch (
  clk, ButtonIn,
  a, b, c, d, e, f, g, dp,
  pos, reset
);

  parameter sim = 0;
  input clk, ButtonIn, reset;
  output a, b, c, d, e, f, g, dp;
  output [3:0] pos;

  wire pulse400Hz, pulse10Hz;
  wire ButtonOut, clr, count;
  wire[3:0] d0, d1, d2, d3;

  // 分频器1
  counter_n #(.n(sim?2:250000), .counter_bits(sim?1:18)) Div1(
    .clk(clk), .en(0'b1), .r(0'b0), .q(), .co(pulse400Hz)
  );

  // 分频器2
  counter_n #(.n(sim?10:40), .counter_bits(sim?4:6)) Div2(
    .clk(clk), .en(pulse400Hz), .r(0'b0), .co(pulse10Hz)
  );

  button_unit #(.sim(sim)) buttonInst(
    .clk(clk), .reset(reset), .ButtonIn(ButtonIn), .ButtonOut(ButtonOut)
  );

  control controlInst(
    .clk(clk), .reset(reset), .in(ButtonOut), .clr(clr), .count(count)
  );

  timing timingInst(
    .clk(clk), .r(clr), .en(pulse10Hz&count), .q0(d0), .qs({d2,d1}), .qm(d3)
  );

  display displayInst(
    .clk(clk), .scan(pulse400Hz), 
    .d0(d0), .d1(d1), .d2(d2), .d3(d3),
    .a(a), .b(b), .c(c), .d(d), .e(e), .f(f), .g(g),
    .pos(pos)
  );

  assign dp = pos[1];

    
endmodule